package com.sctvcloud.bazhong.beans;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.ruihang.generalibrary.ui.util.IListData;
import com.ruihang.generalibrary.utils.DateUtils;
import com.ruihang.generalibrary.utils.IDataDate;
import com.ruihang.generalibrary.utils.IDataMultiDate;
import com.ruihang.generalibrary.utils.IShares;
import com.ruihang.generalibrary.utils.UrlUtils;
import com.sctvcloud.bazhong.application.Constances;
import com.sctvcloud.bazhong.ui.datainf.IAdvanceData;
import com.sctvcloud.bazhong.ui.util.IListShowData;

import java.io.Serializable;
import java.sql.Date;
import java.util.List;

/**
 * Created by liuyu on 2017/8/9.
 */

public class FProgram implements Serializable, IDataDate, IDataMultiDate, IAdvanceData, IListShowData, IShares {
    private static final long serialVersionUID = -7968616526889835789L;

    private String programmeId;
    private String programmeImage;
    private String programmeLength;
    private String programmeTitle;
    private String programmeName;
    private String programmeUrl;
    private String pubTime;
    private String playTotal;
    private List<FProgram> programmeList;
    private String startTime;
    private Date dateTemp;
    private int viewType;
    private String sharedUrl;
    private boolean isSelect;
    /**
     * 是否已经超过时间
     */
    private boolean hasOutTime = true;

    private long startTimeLongTemp = DateUtils.OUTHOUR;
    private SimpleDataDate programDateTemp;

    public String getProgrammeId() {
        return programmeId;
    }

    public void setProgrammeId(String programmeId) {
        this.programmeId = programmeId;
    }

    public String getProgrammeImage() {
        return programmeImage;
    }

    public void setProgrammeImage(String programmeImage) {
        this.programmeImage = programmeImage;
    }

    public String getProgrammeLength() {
        return programmeLength;
    }

    public void setProgrammeLength(String programmeLength) {
        this.programmeLength = programmeLength;
    }

    public String getProgrammeTitle() {
        return programmeTitle;
    }

    public void setProgrammeTitle(String programmeTitle) {
        this.programmeTitle = programmeTitle;
    }

    public String getProgrammeUrl() {
        return programmeUrl;
    }

    public void setProgrammeUrl(String programmeUrl) {
        this.programmeUrl = programmeUrl;
    }

    public String getPubTime() {
        return pubTime;
    }

    public void setPubTime(String pubTime) {
        boolean b = TextUtils.equals(pubTime, this.pubTime);
        this.pubTime = pubTime;
        if (!b) {
            this.dateTemp = null;
        }
    }

    public String getProgrammeName() {
        return programmeName;
    }

    public void setProgrammeName(String programmeName) {
        this.programmeName = programmeName;
    }

    public List<FProgram> getProgrammeList() {
        return programmeList;
    }

    public void setProgrammeList(List<FProgram> programmeList) {
        this.programmeList = programmeList;
    }

    public boolean isHasOutTime() {
        return hasOutTime;
    }

    public void setHasOutTime(boolean hasOutTime) {
        this.hasOutTime = hasOutTime;
    }

    public String getPlayTotal() {
        return playTotal;
    }

    public void setPlayTotal(String playTotal) {
        this.playTotal = playTotal;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        if (!TextUtils.equals(startTime, this.startTime)) {
            startTimeLongTemp = DateUtils.OUTHOUR;
        }
        this.startTime = startTime;
        if (programDateTemp != null) {
            programDateTemp.setDateStr(startTime);
        }
    }

    public int getViewType() {
        return viewType;
    }

    public FProgram setViewType(int viewType) {
        this.viewType = viewType;
        return this;
    }

    public String getSharedUrl() {
        return sharedUrl;
    }

    public FProgram setSharedUrl(String sharedUrl) {
        this.sharedUrl = sharedUrl;
        return this;
    }

    public long getStartTimeLongTemp() {
        return startTimeLongTemp;
    }

    public void setStartTimeLongTemp(long startTimeLongTemp) {
        this.startTimeLongTemp = startTimeLongTemp;
    }

    @Override
    public Date getDataDate() {
        return dateTemp;
    }

    @Override
    public void setDataDate(Date date) {
        this.dateTemp = date;
    }

    @NonNull
    @Override
    public String getDatePattern() {
        return "yyyy-MM-dd HH:mm:ss";
    }

    @Override
    public String getDateString() {
        return pubTime;
    }

    @Override
    public String getDataTitle() {
        return programmeTitle;
    }

    @Override
    public String getDataImg() {
        return programmeImage;
    }

    @Override
    public String getDataTag() {
        return sharedUrl;
    }

    @Override
    public String getDataId() {
        return programmeId;
    }

    @Override
    public int getDataType() {
        return 0;
    }

    @Override
    public int getDataViewType() {
        return viewType;
    }

    @Override
    public IListData getOwner() {
        return null;
    }

    @Override
    public boolean isSubscribe() {
        return hasOutTime;
    }

    @Override
    public String getTime() {
        return startTime;
    }

    @Override
    public IListShowData getOwenerData() {
        return null;
    }

    @Override
    public String getShareTitle() {
        return programmeTitle;
    }

    @Override
    public String getShareH5() {
        return null;
    }

    @Override
    public String getShareImage() {
        return programmeImage;
    }

    @Override
    public String getShareDigest() {
        return null;
    }

    @Override
    public String getShareURL() {
        String shareUrl = UrlUtils.linkUrls(Constances.ST_BASE_URL, sharedUrl) + "?programmeUrl=" + UrlUtils.linkUrls(Constances.ST_BASE_URL, programmeUrl) + "&programmeTitle="
                + stringreplace(programmeTitle) + "&programmeImage=" + UrlUtils.linkUrls(Constances.ST_BASE_URL, programmeImage);
        return shareUrl;
    }

    public boolean isSelect() {
        return isSelect;
    }

    public void setSelect(boolean select) {
        isSelect = select;
    }

    @Override
    public String toString() {
        return "FProgram{" +
                "programmeId='" + programmeId + '\'' +
                ", programmeImage='" + programmeImage + '\'' +
                ", programmeLength='" + programmeLength + '\'' +
                ", programmeTitle='" + programmeTitle + '\'' +
                ", programmeName='" + programmeName + '\'' +
                ", programmeUrl='" + programmeUrl + '\'' +
                ", pubTime='" + pubTime + '\'' +
                ", playTotal='" + playTotal + '\'' +
                ", programmeList=" + programmeList +
                ", startTime='" + startTime + '\'' +
                ", dateTemp=" + dateTemp +
                ", viewType=" + viewType +
                ", sharedUrl='" + sharedUrl + '\'' +
                ", isSelect=" + isSelect +
                ", hasOutTime=" + hasOutTime +
                ", startTimeLongTemp=" + startTimeLongTemp +
                '}';
    }

    @Override
    public IDataDate getDataDateInterface(int mode) {
        initProgramDate();
        return programDateTemp;
    }

    protected void initProgramDate() {
        if (programDateTemp == null) {
            programDateTemp = new SimpleDataDate("HH:mm:ss", startTime);
        } else {
            programDateTemp.setDateStr(startTime);
        }
    }


    protected String stringreplace(String programmeTitle) {
        if (!TextUtils.isEmpty(programmeTitle)) {
            if (programmeTitle.contains("“")) {
                programmeTitle = programmeTitle.replace("“", "'");
            }
            if (programmeTitle.contains("”")) {
                programmeTitle = programmeTitle.replace("”", "'");
            }
            if (programmeTitle.contains("——")) {
                programmeTitle = programmeTitle.replace("——", "--");
            }
            if (programmeTitle.contains("《")) {
                programmeTitle = programmeTitle.replace("《", "<");
            }
            if (programmeTitle.contains("》")) {
                programmeTitle = programmeTitle.replace("》", ">");
            }
            if (programmeTitle.contains("（")) {
                programmeTitle = programmeTitle.replace("（", "(");
            }
            if (programmeTitle.contains("）")) {
                programmeTitle = programmeTitle.replace("）", ")");
            }
            if (programmeTitle.contains("：")) {
                programmeTitle = programmeTitle.replace("：", ":");
            }
            if (programmeTitle.contains("！")) {
                programmeTitle = programmeTitle.replace("！", "!");
            }
            return programmeTitle;
        }
        return null;
    }
}
